#include <iostream>
#include <memory>
using namespace std;

class Point 
:public enable_shared_from_this<Point>
{
public:

    void print()
    {
        cout << "(" << _ix
            << "," << _iy
            << ")" << endl;
    }
    Point(int x, int y)
    :_ix(x)
    ,_iy(y)
    {
        cout << "Point(int * 2)" << endl;
    }
    ~Point() {
        cout << "~Point()" << endl;
    }

    shared_ptr<Point> addPoint(Point* pt) {
        _ix += pt->_ix;
        _iy += pt->_iy;
        return shared_from_this();
    }
private:
    int _ix;
    int _iy;
};
void test()
{
    shared_ptr<Point> sp(new Point(1, 2));
    shared_ptr<Point> sp2(new Point(3, 4));

    cout << sp.get() << endl;
    shared_ptr<Point> sp3(sp->addPoint(sp2.get()));
    cout << sp3.get() << endl;
    cout << sp3.use_count() << endl;
    cout << "sp3 = ";
    sp3->print();
}
int main()
{
    test();
    return 0;
}